/**
 * Created by renzhiqiang on 18/2/28.
 */
var gp = require('gulp');
var gulp_tpl = require('gulp-template');
var inquirer = require('inquirer');
function ucfirst(str) {
    var str = str.toLowerCase();
    str = str.replace(/\b\w+\b/g, function (word) {
        return word.substring(0, 1).toUpperCase() + word.substring(1);
    });
    return str;
}
gp.task('page',function(){
    inquirer.prompt([
        {
            type: 'input',
            name: 'router',
            message: '请输入文件夹名称和路由信息',
            default: "" // 从运行参数中获取值作为 name 的默认值。
        },

    ]).then(function (answers) {
        console.info(__dirname);
        gp.src([__dirname + '/templates/template/routes/**'])  // Note use of __dirname to be relative to generator
            .pipe(gulp_tpl({
                'router':answers.router,
                'addRouter':"add"+ucfirst(answers.router)
            }))                  // Lodash template support
            // .pipe(conflict('./','a'))                    // Confirms overwrites on file conflicts
            .pipe(gp.dest('./build/routes/'+answers.router))                  // Without __dirname here = relative to cwd
            // .on('finish', function () {
            //     done();                                // Finished!
            // });
        gp.src([__dirname + '/templates/template/models/**'])  // Note use of __dirname to be relative to generator
            .pipe(gulp_tpl({
                'router':answers.router,
                'addRouter':"add"+ucfirst(answers.router)
            }))                  // Lodash template support
            // .pipe(conflict('./','a'))                    // Confirms overwrites on file conflicts
            .pipe(gp.dest('./build/models/'+answers.router))                        // Without __dirname here = relative to cwd
            // .on('finish', function () {
            //     done();                                // Finished!
            // });
        gp.src([__dirname + '/templates/template/services/**'])  // Note use of __dirname to be relative to generator
            .pipe(gulp_tpl({
                'router':answers.router,
                'addRouter':"add"+ucfirst(answers.router)
            }))                  // Lodash template support
            // .pipe(conflict('./','a'))                    // Confirms overwrites on file conflicts
            .pipe(gp.dest('./build/services/'+answers.router))                    // Without __dirname here = relative to cwd
            // .on('finish', function () {
            //     done();                                // Finished!
            // });
    });
    // gp.src(['./html/.*','./html/**'])
    //     .pipe(gulp_tpl({
    //         'router':18
    //     }))
    //     .pipe(gp.dest('./build'));
})
